﻿@using Smartstore.Web.Models.Cart;

@model WishlistModel

@{
    Assets.BodyAttributes.AppendCssClass("no-offcanvas-cart");
    Assets.AppendTitleParts(T("PageTitle.Wishlist").Value);
    Assets.AddMetaRobots();

    var modelHasItems = Model.Items.Any();
}

<div class="page wishlist-page">
    <div class="page-title">
        <h1 class="mb-0">@(Model.IsEditable ? T("Wishlist") : T("Wishlist.WishlistOf", Model.CustomerFullname))</h1>
    </div>
    <div class="page-body">
        <div class="wishlist-content cart-content" 
             data-update-item-url="@Url.Action("UpdateCartItem", "ShoppingCart")"
             data-empty-text=@T("Wishlist.CartIsEmpty").JsValue>
            <zone name="wishlist_items_top" />

            @if (modelHasItems)
            {
                <div sm-if="Model.Warnings.Count > 0" class="alert alert-danger">
                    @foreach (var warning in Model.Warnings)
                    {
                        <p>@Html.Raw(warning)</p>
                    }
                </div>

                <form asp-route="Wishlist" method="post">
                    <div class="cart-container mb-3">
                        @* Cart Items *@
                        <div id="cart-items" class="cart cart-editable">
                            <div class="cart-body">
                                <partial name="WishlistItems" model="Model" />
                            </div>
                        </div>
                    </div>

                    <div class="common-buttons hstack gap-1">
                        @if (Model.IsEditable && Model.EmailWishlistEnabled)
                        {
                            <a asp-action="EmailWishlist" rel="nofollow" class="btn btn-secondary">
                                <i class="fa fa-share"></i>
                                <span>@T("Wishlist.EmailAFriend")</span>
                            </a>
                        }
                        @if (!Model.IsEditable && Model.DisplayAddToCart)
                        {
                            <button type="submit" name="addtocartbutton" value="addtocartbutton" class="btn btn-primary">
                                <i class="fa fa-cart-arrow-down"></i>
                                <span>@T("ShoppingCart.AddToCart")</span>
                            </button>
                        }
                    </div>
                </form>
            }
            else
            {
                <div class="alert alert-warning fade show">
                    @T("Wishlist.CartIsEmpty")
                </div>
            }
        </div>

        <div sm-if="Model.IsEditable && modelHasItems" class="share-info my-4">
            <h5 class="share-label mb-1">
                <i class="far fa-share-square"></i>
                @T("Wishlist.YourWishlistURL")
            </h5>
            <a asp-route="Wishlist" asp-route-customerGuid="@Model.CustomerGuid" class="share-link">
                @Url.RouteUrl("Wishlist", new { customerGuid = Model.CustomerGuid }, Context.Request.IsHttps ? "https" : "http", Context.Request.Host.Value)
            </a>
        </div>
    </div>
</div>

@if (Model.IsEditable)
{
    <script src="~/js/public.refreshcart.js" sm-target-zone="scripts"></script>
}